package com.fr.chart;

import com.fr.base.xml.XMLPrintWriter;
import com.fr.base.xml.XMLableReader;
import com.fr.chart.base.equals.Equals;
import com.fr.chart.core.RectangleGlyph;
import com.fr.chart.core.glyph.ChartGlyph;
import com.fr.chart.core.glyph.LegendGlyph;
import com.fr.chart.core.glyph.PlotGlyph;
import com.fr.chart.core.glyph.TextGlyph;
import com.fr.chart.math.Plot3D;
import com.fr.report.io.xml.ReportXMLUtils;
import java.awt.geom.Dimension2D;
import java.awt.geom.Rectangle2D;
import java.awt.geom.Rectangle2D.Double;
import java.awt.geom.RoundRectangle2D.Double;

public class ChartGlyphLayout
{
  public static final String XML_TAG = "ChartGlyphLayout";
  private Rectangle2D chartGlyphBounds = null;

  public ChartGlyphLayout()
  {
  }

  public ChartGlyphLayout(Rectangle2D paramRectangle2D)
  {
    this.chartGlyphBounds = paramRectangle2D;
  }

  public void setLayoutBounds(Rectangle2D paramRectangle2D)
  {
    this.chartGlyphBounds = paramRectangle2D;
  }

  public Rectangle2D getChartGlyphBounds()
  {
    return this.chartGlyphBounds;
  }

  public void doLayout(RectangleGlyph paramRectangleGlyph)
  {
    if (paramRectangleGlyph == null)
      return;
    double d1 = 10.0D;
    double d2 = 0.03D;
    if (paramRectangleGlyph instanceof ChartGlyph)
    {
      Rectangle2D.Double localDouble2;
      ChartGlyph localChartGlyph = (ChartGlyph)paramRectangleGlyph;
      TextGlyph localTextGlyph = localChartGlyph.getTitleGlyph();
      Rectangle2D localRectangle2D1 = this.chartGlyphBounds.getBounds2D();
      if (localTextGlyph != null)
      {
        localObject = localTextGlyph.preferredDimension();
        Rectangle2D.Double localDouble1 = new Rectangle2D.Double((localRectangle2D1.getWidth() - ((Dimension2D)localObject).getWidth()) / 2.0D, localRectangle2D1.getY() + localRectangle2D1.getHeight() * d2, ((Dimension2D)localObject).getWidth(), ((Dimension2D)localObject).getHeight());
        localRectangle2D1.setFrame(localRectangle2D1.getX(), localRectangle2D1.getY() + ((Dimension2D)localObject).getHeight() + localRectangle2D1.getHeight() * d2, localRectangle2D1.getWidth(), localRectangle2D1.getHeight() - ((Dimension2D)localObject).getHeight() - localRectangle2D1.getHeight() * d2);
        if (localTextGlyph.isRoundBorder())
          localTextGlyph.setBounds(new RoundRectangle2D.Double(localDouble1.getX(), localDouble1.getY(), localDouble1.getWidth(), localDouble1.getHeight(), d1, d1));
        else
          localTextGlyph.setBounds(localDouble1);
      }
      Object localObject = localChartGlyph.getLegendGlyph();
      if (localObject != null)
      {
        int i = ((LegendGlyph)localObject).getPosition();
        localDouble2 = null;
        double d3 = 0.1D;
        double d4 = 0.3D;
        double d5 = 1.0D - d4 * 2.0D;
        if (((LegendGlyph)localObject).isAutoAdjustSize())
        {
          double d6 = 0.0D;
          double d8 = 0.0D;
          double d10 = 1.0D;
          double d12 = 1.0D;
          double d14 = 0.0D;
          double d16 = 0.0D;
          double d18 = 1.0D;
          double d19 = 1.0D;
          if (i == 4)
          {
            d6 = localRectangle2D1.getWidth() * (1.0D - d2 - d3);
            d8 = localRectangle2D1.getHeight() * d4;
            d10 = d3;
            d12 = d5;
            d18 = 1.0D - d2 - d3;
          }
          else if (i == 2)
          {
            d6 = localRectangle2D1.getWidth() * d2;
            d8 = localRectangle2D1.getHeight() * d4;
            d10 = d3;
            d12 = d5;
            d14 = localRectangle2D1.getWidth() * (d2 + d3);
            d18 = 1.0D - d2 - d3;
          }
          else if (i == 3)
          {
            d6 = localRectangle2D1.getWidth() * d4;
            d8 = localRectangle2D1.getHeight() * (1.0D - d2 - d3);
            d10 = d5;
            d12 = d3;
            d19 = 1.0D - d2 - d3;
          }
          else
          {
            d6 = localRectangle2D1.getWidth() * d4;
            d8 = localRectangle2D1.getHeight() * d2;
            d10 = d5;
            d12 = d3;
            d16 = localRectangle2D1.getHeight() * (d2 + d3);
            d19 = 1.0D - d2 - d3;
          }
          localDouble2 = new Rectangle2D.Double(localRectangle2D1.getX() + d6, localRectangle2D1.getY() + d8, localRectangle2D1.getWidth() * d10, localRectangle2D1.getHeight() * d12);
          localRectangle2D1.setFrame(localRectangle2D1.getX() + d14, localRectangle2D1.getY() + d16, localRectangle2D1.getWidth() * d18, localRectangle2D1.getHeight() * d19);
          ((LegendGlyph)localObject).calculateBounds(localDouble2);
        }
        else
        {
          Dimension2D localDimension2D = ((LegendGlyph)localObject).prefferedSize();
          localDimension2D.setSize(Math.min(localDimension2D.getWidth(), localRectangle2D1.getWidth()), Math.min(localDimension2D.getHeight(), localRectangle2D1.getHeight()));
          double d7 = 0.0D;
          double d9 = 0.0D;
          double d11 = 0.0D;
          double d13 = 0.0D;
          double d15 = 0.0D;
          double d17 = 0.0D;
          if (i == 1)
          {
            d7 = (localRectangle2D1.getWidth() - localDimension2D.getWidth()) / 2.0D;
            d9 = localRectangle2D1.getHeight() * d2;
            d13 = localDimension2D.getHeight() + localRectangle2D1.getHeight() * d2;
            d17 = -localDimension2D.getHeight() - localRectangle2D1.getHeight() * d2;
          }
          else if (i == 4)
          {
            d7 = localRectangle2D1.getWidth() - localDimension2D.getWidth() - localRectangle2D1.getWidth() * d2;
            d9 = (localRectangle2D1.getHeight() - localDimension2D.getHeight()) / 2.0D;
            d15 = -localDimension2D.getWidth() - localRectangle2D1.getWidth() * d2;
          }
          else if (i == 3)
          {
            d7 = (localRectangle2D1.getWidth() - localDimension2D.getWidth()) / 2.0D;
            d9 = localRectangle2D1.getHeight() - localDimension2D.getHeight() - localRectangle2D1.getHeight() * d2;
            d17 = -localDimension2D.getHeight() - localRectangle2D1.getHeight() * d2;
          }
          else if (i == 2)
          {
            d7 = localRectangle2D1.getWidth() * d2;
            d9 = (localRectangle2D1.getHeight() - localDimension2D.getHeight()) / 2.0D;
            d11 = localDimension2D.getWidth() + localRectangle2D1.getWidth() * d2;
            d15 = -localDimension2D.getWidth() - localRectangle2D1.getWidth() * d2;
          }
          localDouble2 = new Rectangle2D.Double(localRectangle2D1.getX() + d7, localRectangle2D1.getY() + d9, localDimension2D.getWidth(), localDimension2D.getHeight());
          localRectangle2D1.setFrame(localRectangle2D1.getX() + d11, localRectangle2D1.getY() + d13, localRectangle2D1.getWidth() + d15, localRectangle2D1.getHeight() + d17);
        }
        if (((LegendGlyph)localObject).isRoundRect())
          ((LegendGlyph)localObject).setBounds(new RoundRectangle2D.Double(localDouble2.getX(), localDouble2.getY(), localDouble2.getWidth(), localDouble2.getHeight(), d1, d1));
        else
          ((LegendGlyph)localObject).setBounds(localDouble2);
        ((LegendGlyph)localObject).refreshItemBounds();
      }
      PlotGlyph localPlotGlyph = localChartGlyph.getPlotGlyph();
      if (localPlotGlyph != null)
      {
        localDouble2 = new Rectangle2D.Double(localRectangle2D1.getX() + 0.05D * localRectangle2D1.getWidth(), localRectangle2D1.getY() + 0.1D * localRectangle2D1.getHeight(), 0.9D * localRectangle2D1.getWidth(), 0.83D * localRectangle2D1.getHeight());
        if (localPlotGlyph instanceof Plot3D)
          localDouble2 = new Rectangle2D.Double(localRectangle2D1.getX() + 0.05D * localRectangle2D1.getWidth(), localRectangle2D1.getY() + 0.25D * localRectangle2D1.getHeight(), 0.8D * localRectangle2D1.getWidth(), 0.7D * localRectangle2D1.getHeight());
        localPlotGlyph.setBounds(localDouble2);
        localPlotGlyph.layoutAxisGlyph();
        localPlotGlyph.layoutDataSeriesGlyph();
        if (localPlotGlyph.isRoundBorder())
        {
          Rectangle2D localRectangle2D2 = localPlotGlyph.getBounds();
          localPlotGlyph.setBounds(new RoundRectangle2D.Double(localRectangle2D2.getX(), localRectangle2D2.getY(), localRectangle2D2.getWidth(), localRectangle2D2.getHeight(), d1, d1));
        }
      }
    }
  }

  public void writeXML(XMLPrintWriter paramXMLPrintWriter)
  {
    paramXMLPrintWriter.startTAG("ChartGlyphLayout");
    if (this.chartGlyphBounds != null)
      ReportXMLUtils.writeRectangle2D(paramXMLPrintWriter, this.chartGlyphBounds);
    paramXMLPrintWriter.end();
  }

  public void readXML(XMLableReader paramXMLableReader)
  {
    if (paramXMLableReader.isChildNode())
    {
      String str = paramXMLableReader.getTagName();
      if (str.equals("Rectangle2D"))
        this.chartGlyphBounds = ReportXMLUtils.readRectangle2D(paramXMLableReader);
    }
  }

  public boolean equals(Object paramObject)
  {
    if (!(paramObject instanceof ChartGlyphLayout))
      return false;
    ChartGlyphLayout localChartGlyphLayout = (ChartGlyphLayout)paramObject;
    return (Equals.equals(localChartGlyphLayout.chartGlyphBounds, this.chartGlyphBounds));
  }

  public Object clone()
    throws CloneNotSupportedException
  {
    ChartGlyphLayout localChartGlyphLayout = new ChartGlyphLayout();
    if (this.chartGlyphBounds != null)
      localChartGlyphLayout.chartGlyphBounds = ((Rectangle2D)this.chartGlyphBounds.clone());
    return localChartGlyphLayout;
  }
}